package demo.collection;

import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Random;
import java.util.Set;
import java.util.TreeSet;

public class DemoSet {
	private HashSet<Integer> hsDemo = new HashSet<Integer>();
	private LinkedHashSet<Integer> lsDemo = new LinkedHashSet<Integer>();
	private TreeSet<Integer> tsDemo = new TreeSet<Integer>();
	
	public static void main(String[] args) {
		int length = 1000000;
		DemoSet ds = new DemoSet();
		ds.init(length);
//		System.out.println("hash set: " + ds.insert(ds.hsDemo, ds.tmp));
//		System.out.println("linked hash set: " + ds.insert(ds.lsDemo, ds.tmp));
//		System.out.println("tree set: " + ds.insert(ds.tsDemo, ds.tmp));
		
		System.out.println("Hash set");
		ds.print(ds.hsDemo);
		System.out.println("===========");
		
		System.out.println("Linked hash set");
		ds.print(ds.lsDemo);
		System.out.println("===========");
		
		System.out.println("Tree set");
		ds.print(ds.tsDemo);
	}
	
	private void init(Integer length) {
		Random rd = new Random();
		for (int i = 0; i < length; i++) {
			int a = rd.nextInt();
			hsDemo.add(a);
			lsDemo.add(a);
			tsDemo.add(a);
		}
	}
	
	private void print(Set<Integer> set){
		long start = System.currentTimeMillis();
		Iterator<Integer> ite = set.iterator();
		while (ite.hasNext()){
			Integer value = ite.next();
			System.out.print(" " + value);
		}
		long end = System.currentTimeMillis();
		System.out.println("");
		System.out.println("Thoi gian: " + (end - start));
	}
	
}
